package org.song.service.impl;

import org.song.mapper.MessageMapper;
import org.song.model.dto.MessageDto;
import org.song.model.vo.Message;
import org.song.service.MessageService;
import org.song.service.impl.common.AbstractBaseServiceImpl;
import org.song.util.SnowflakeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class MessageServiceImpl extends AbstractBaseServiceImpl implements MessageService {

    @Autowired( required = true )
    @Qualifier( value = "messageMapper")
    private MessageMapper messageMapper;

    @Override
    public List<Message> listMessages( @NonNull MessageDto messageDto) {
        return messageMapper.listMessages(messageDto);
    }
    

    @Override
    public int deleteMessage( @NonNull Message message) {
        return messageMapper.deleteMessage(message);
    }

    @Override
    public int insertMessage( @NonNull Message message) {
        message.setId( SnowflakeUtil.getNextLongId() );
        message.setCreateTime( new Date());
        return messageMapper.insertMessage(message);
    }

    @Override
    public int updateMessage( @NonNull Message message) {
        return messageMapper.updateMessage(message);
    }
    
}
